package com.bwie.bwedu.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Xml;

import com.bwie.bwedu.bean.Version;

import org.xmlpull.v1.XmlPullParser;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;


public class VersionUtil {

	public static Version getVersion(String xml){
		Version v=new Version();
		try {
			InputStream stream = new FileInputStream(xml);
			XmlPullParser parser = Xml.newPullParser();
			parser.setInput(stream, "utf-8");
			int type = parser.getEventType();
			while(type!=XmlPullParser.END_DOCUMENT){
				switch (type) {
				case XmlPullParser.START_TAG:
					if ("version".equals(parser.getName())) {
						v.setVersion(parser.nextText());
					}else if ("info".equals(parser.getName())) {
						v.setInfo(parser.nextText());
					}else if ("url".equals(parser.getName())) {
						v.setUrl(parser.nextText());
					}
					break;
				}
				type=parser.next();
			}
			return v;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static void installApk(File file,Context context) {
		Intent intent = new Intent();
		//执行动作
		intent.setAction(Intent.ACTION_VIEW);
		//执行的数据类型
		intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
	}  
}
